package com.zhaohang.cn.mybasicactivity;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;

import com.squareup.leakcanary.LeakCanary;
import com.zhaohang.cn.constant.ConstantUtils;
import com.zhaohang.cn.utils.CrashHandler;
import com.zhaohang.cn.utils.SaveUtils;


/**
 * 作者: 赵航
 * 创建时间: 2018/8/11 15:24
 * 描述:
 */
public class CompontApplayCation extends Application {

    public static Context context;
    public static Handler mainHandler;
    public static int mStatbarHight;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        mainHandler = new Handler(Looper.getMainLooper());

        //检测内存泄漏
        LeakCanary.install(CompontApplayCation.this);
        //异常处理
        creashDeal();

        mStatbarHight = getStatusBarHeight();
    }

    private void creashDeal() {
        //获取全局未捕获的异常
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(getApplicationContext());
        //获取异常文件的路径
        String string = SaveUtils.getString(ConstantUtils.CRASHFILE);
        //上传异常文件
        if (!TextUtils.isEmpty(string)) {
            //            File dir = new File(string);
            //            if (dir.exists()) {
            //                OkHttpUtils.post()
            //                        .addFile("mFile", "test.txt", dir)//
            //                        .url("www.baidu.com")
            //                        .build()
            //                        .execute(new StringCallback() {
            //                            @Override
            //                            public void onError(Call call, Exception e, int id) {
            //                                //上传文件失败
            //                            }
            //
            //                            @Override
            //                            public void onResponse(String response, int id) {
            //                                //上传文件成功
            //                                SaveUtils.setString("", ConstantUtils.CRASHFILE);
            //                            }
            //                        });
            //            }
        }

    }

    public int getStatusBarHeight() {

        Resources resources =getResources();

        int resourceId = resources.getIdentifier("status_bar_height","dimen","android");

        int height = resources.getDimensionPixelSize(resourceId);

        return height;

    }

}

